<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%-- 引入页面头 --%>
<%@ include file="/pageHead.jsp"%>
<form name="form1" id="form1" action="<%-- ${systemctx}/sample/saveSample.web --%>" method="post">
	<div class="pageMain">
		<div class="pageTitle">
		<%=MessageResourcesUtils.getMessage(request, "systemmanage.servicemanagement.title") %>
		<span></span>
		<%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesList.title") %>
		<span></span>
		<%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesList.servicelist") %>
		</div>
		<div class="pageBody">
			<div class="form-group">
				<ul>
					<li>
						<i></i>
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesList.servicename") %></label>
						<span><input type="text" class="input-sm" id="servicename" name="servicename" value="" /></span>
					</li>
				</ul>	
			</div>	
		</div>
		<div class="button-group">
			<input type="button" class="btn btn-default" id="butQuery" name="butQuery" value="<%=MessageResourcesUtils.getMessage(request, "common.button.query") %>" />
			<input type="button" class="btn btn-default" onclick="servicesAdd()" value="<%=MessageResourcesUtils.getMessage(request, "common.button.add") %>" />
			<input type="button" class="btn btn-default" id="butStart" name="butStart" value="<%=MessageResourcesUtils.getMessage(request, "dailyoperation.storechargemanage.button.start") %>" />
			<input type="button" class="btn btn-default" id="butStop" name="butStop" value="<%=MessageResourcesUtils.getMessage(request, "dailyoperation.storechargemanage.button.stop") %>" />
		</div>
		<table width="100%">
			<tbody>
				<tr>
					<td>
						<table id="datagrid"></table>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
</form>
<script type="text/javascript">
	$(document).ready(
					function() {
						$('#butStart').click(function(){
							var data=$('#datagrid').datagrid('getChecked');
							if(data!=null && data.length>0 && data.length != 0){
								var ids="";
								for(var i=0;i<data.length;i++)
								{
									ids=data[i].id+";"+ids;
								}
								if (ids != '') {
									ids = ids.substring(0,ids.length-1);
								}
								if(confirm('<%=MessageResourcesUtils.getMessage(request,"dailyoperation.storechargemanage.alert.confirmstart")%>'))
								{
									// 显示进度条
									showSending();
									$.ajax({
										type: 'POST',
									    url: '${systemctx}/dailyoperation/services/startOrStopServices.json?flag=1&ids='+ids,
									    dataType: 'json',
									    success: function(data) {
									    	//关闭执行...
											closeSending();
									    	if(data.messagetype == 1){
									    		alert(data.message);
									    		$('#datagrid').datagrid('reload',$('#form1').serializeObject());
												$('#datagrid').datagrid('clearSelections');
									    	}else {
									    		alert(data.message);
									    		return;
									    	}
									    }
									});
								}
							}else{
								alert('<%=MessageResourcesUtils.getMessage(request, "dailyoperation.storechargemanage.alert.warning")%>');
								return;
							}
						});
						$('#butStop').click(function(){
							var data=$('#datagrid').datagrid('getChecked');
							if(data!=null && data.length>0 && data.length != 0){
								var ids="";
								for(var i=0;i<data.length;i++){
									ids=data[i].id+";"+ids;
								}
								if (ids != '') {
									ids = ids.substring(0,ids.length-1);
								}
								if(confirm('<%=MessageResourcesUtils.getMessage(request,"dailyoperation.storechargemanage.alert.confirmstop")%>')){
									// 显示进度条
									showSending();
									$.ajax({
										type: 'POST',
									    url: '${systemctx}/dailyoperation/services/startOrStopServices.json?flag=2&ids='+ids,
									    dataType: 'json',
									    success: function(data) {
									    	//关闭执行...
											closeSending();
									    	if(data.messagetype == 1){
									    		alert(data.message);
									    		$('#datagrid').datagrid('reload',$('#form1').serializeObject());
												$('#datagrid').datagrid('clearSelections');
									    	}else {
									    		alert(data.message);
									    		return;
									    	}
									    }
									});
								}
							}else{
								alert('<%=MessageResourcesUtils.getMessage(request, "dailyoperation.storechargemanage.alert.warning")%>');
								return;
							}
						});	
						//加载分页控件 datagrid
						$('#datagrid').issdatagrid(
										{
											formid : 'form1',
											title : '<%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesList.servicelist") %>',
											width : 'auto',
											nowrap : true,
											autoRowHeight : false,
											singleSelect : false,
											striped : true,
											//collapsible:true,
											url : '${systemctx}/dailyoperation/services/queryServicesListInfoDataGrid.json',
											sortName : 'modifytime',
											sortOrder : 'desc',
											remoteSort : true,
											idField : 'id',
											pagination : true,
											rownumbers : true,
											showFooter : true,
											queryParams:$('#form1').serializeObject(),
											columns : [ [
											{field:'ck', checkbox:true
											},{
												field : 'id',
												title : '<%=MessageResourcesUtils.getMessage(request, "common.button.operation") %>',
												width : 100,
												align : 'center',
												formatter : operate
											},{
												title : '<%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesList.servicenum") %>',
												field : 'servicenum',
												width : 100,
												sortable : true,
												align : 'left',
												formatter: function(value,row,index){
													return "<a href=\"javascript:void(0);\" onclick=\"view('"+row.id+"')\">"+value+"</a>";
											}
											}, {
												title : '<%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesList.servicename") %>',
												field : 'servicename',
												width : 120,
												sortable : true,
												align : 'left'
											}, {
												title : '<%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.storeservicesguajieList.checkstatus") %>',
												field : 'checkstatus',
												width : 100,
												sortable : true,
												align : 'center'
											}, {
												title : '<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.bussisstatus") %>',
												field : 'businessstatus',
												width : 100,
												sortable : true,
												align : 'center'
											},
											{field : 'candelete' ,hidden : true} ] ],
											onLoadSuccess : function(data) {

											}
										});

						$('#butQuery').click(
								function() {
									$('#datagrid').datagrid('load',
											$('#form1').serializeObject());
						});

						function operate(val, row) {
							var checkstatus = row.checkstatus;
							if(checkstatus == '<%=SysConstant.CheckStatus.getName(SysConstant.CheckStatus.CHECKED) %>'){
								return '<a href="javascript:void(0);" class="easyui-linkbutton" onclick="servicesUpdate('
								+ val
								+ ')"><%=MessageResourcesUtils.getMessage(request, "common.button.update") %></a> <a disabled="disabled" class="easyui-linkbutton disabled" style="color:grey"><%=MessageResourcesUtils.getMessage(request, "common.button.delete") %></a> ';
							}else{
								return '<a href="javascript:void(0);" class="easyui-linkbutton" onclick="servicesUpdate('
								+ val
								+ ')"><%=MessageResourcesUtils.getMessage(request, "common.button.update") %></a> <a href="javascript:void(0);" class="easyui-linkbutton" onclick="servicesDelete('
								+ val + ')"><%=MessageResourcesUtils.getMessage(request, "common.button.delete") %></a> ';
							}
						}
					});
	function servicesAdd() {
		$(this).isswindow({
			noheader : true,
			url : '${systemctx}/dailyoperation/services/toAddServices.web'
		});
	}
	
	function servicesUpdate(val) {
		var id = val;
		$(this).isswindow({
			noheader : true,
			url : '${systemctx}/dailyoperation/services/toUpdateServices.web?id=' + id
		});
	}
	
	function view(val){
		var id = val
		$(this).isswindow({
			noheader : true,
			url : '${systemctx}/dailyoperation/services/toViewServices.web?id='+id
		});
	}
	
	function servicesDelete(val) {
		var id = val;
		if (confirm("<%=MessageResourcesUtils.getMessage(request, "alertinfo.common.jsp.alert2") %>")) {
			//正在执行...
			showSending();
			$.ajax({
				type : 'GET',
				url : '${systemctx}/dailyoperation/services/deleteServices.json?id=' + id,
				dataType : 'json',
				success : function(data) {
					//关闭执行...
					closeSending();
					//显示AJAX请求后的提示信息
					$.fn.ajaxmessage(data);
					$('#datagrid').datagrid('reload',
							$('#form1').serializeObject());
					$('#datagrid').datagrid('clearSelections');
				}
			});
		}
	}
</script>
<%-- 引入页面尾 --%>
<%@ include file="/pageFloor.jsp"%>